<?php
class mdl_member_info extends ujn_model {
	public function makeMember($mid, $puid) {
		$_sql = "insert into {$this->tbl_name} set `mid` = '$mid', `vote` = '0', `exp` = '1', `level` = '1', `vip` = '0', `viptime` = '0', `mstatus` = '0', `mactivetime` = '" . NOW . "', `mentercount` = '1', `mtime` = '" . NOW . "', `puid` = '{$puid}';";
		$this->_db->query($_sql);
		if($this->_db->affectedRows() > 0) {
			$newuid = $this->_db->insertID();

			return $newuid;
		} else {
			return false;
		}
	}	
	
	public function getMember($mid) {
		$_sql = "select * from {$this->tbl_name} where `mid` = '$mid' limit 1;";
		return $this->_db->getOne($_sql, MYSQL_ASSOC);
	}	
	
	public function getMemberByUID($mid, $puid) {
		$d = $this->getMember($mid);
		if(empty($d)) {
			$this->makeMember($mid, $puid);
			$d['mid'] = $mid;
			$d['puid'] = $puid;
			$d['vote'] = 0;
			$d['level'] = $d['exp'] = 1;
			$d['mactivetime'] = $d['mtime'] = NOW;
			$d['is_register'] = '1';
		}

		return $d;
	}	
	
	protected function __construct() {
		parent::__construct();
		$this->db_name		= 'love_a_love';
		$this->tbl_name		= "`{$this->db_name}`.`love_members`"; 
		$this->_db			= $this->mysql();
	}


    /**
     * 单例模型
     * @return mdl_member_info
     */
	static function getInstance() {
        return parent::getInstance(__CLASS__);
	}
}